Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nice-grpc-common

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nice-grpc-common

Common stuff for nice-grpc and nice-grpc-web

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
116K
decreased by-11.43%
Maintainers
1
Weekly downloads
 
Created

What is nice-grpc-common?

The nice-grpc-common package provides common utilities and types for building gRPC services with the nice-grpc framework. It simplifies the process of creating and managing gRPC services in Node.js, offering a more user-friendly API compared to the standard grpc package.

What are nice-grpc-common's main functionalities?

Creating a gRPC Service

This code demonstrates how to create a simple gRPC service using nice-grpc-common. The service has a single method, sayHello, which returns a greeting message.

const { createServer } = require('nice-grpc');
const { createServiceDefinition } = require('nice-grpc-common');

const serviceDefinition = createServiceDefinition({
  sayHello: async (request) => {
    return { message: `Hello, ${request.name}!` };
  },
});

const server = createServer();
server.add(serviceDefinition);

server.listen('0.0.0.0:50051');

Client Interceptors

This code demonstrates how to create and use a client interceptor with nice-grpc-common. The interceptor logs the method being called before proceeding with the gRPC call.

const { createChannel, createClient } = require('nice-grpc');
const { createClientInterceptor } = require('nice-grpc-common');

const loggingInterceptor = createClientInterceptor(async (call, method, options) => {
  console.log(`Calling method: ${method.path}`);
  return call(method, options);
});

const channel = createChannel('localhost:50051');
const client = createClient(serviceDefinition, channel, { interceptors: [loggingInterceptor] });

client.sayHello({ name: 'World' }).then(response => {
  console.log(response.message);
});

Server Interceptors

This code demonstrates how to create and use a server interceptor with nice-grpc-common. The interceptor logs the method being called before proceeding with the gRPC call.

const { createServer } = require('nice-grpc');
const { createServerInterceptor } = require('nice-grpc-common');

const loggingInterceptor = createServerInterceptor(async (call, method, options) => {
  console.log(`Received call to method: ${method.path}`);
  return call(method, options);
});

const server = createServer({ interceptors: [loggingInterceptor] });
server.add(serviceDefinition);

server.listen('0.0.0.0:50051');

Other packages similar to nice-grpc-common

FAQs

Package last updated on 18 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc